import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/user',
    name: 'index',
    meta:{
      name:'后台管理系统'
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/index.vue'),
    children: [
      {
        path: 'monitoringScreen',//以“/”开头的嵌套路径会被当作根路径，所以子路由上不用加“/”;在生成路由时，主路由上的path会被自动添加到子路由之前，所以子路由上的path不用在重新声明主路由上的path了。
        name: '监控大屏',
        component: () => import(/* webpackChunkName: "about" */ '../views/monitoringScreen/index')
      },
      {
        path: 'dataCenter',
        name: '数据中心',
        component: () => import('../views/dataCenter/index'),
        children:[
          {
            path: 'dataStatistics',
            name: '数据分析',
            component: () => import('../views/dataCenter/dataStatistics'),
          },
          {
            path: 'historicalRecords',
            name: '历史记录',
            component: () => import('../views/dataCenter/historicalRecords'),
          },
          {
            path: 'onlineOffline',
            name: '设备上下线',
            component: () => import('../views/dataCenter/onlineOffline'),
          }
        ]
      },
      {
        path: 'equipmentOperation',
        name: '设备运维',
        component: () => import('../views/equipmentOperation/index')
      },
      {
        path: 'deviceManager',
        name: '设备管理',
        component: () => import('../views/deviceManager/index')
      },
      {
        path: 'otherExtend',
        name: '其它扩展',
        component: () => import('../views/otherExtend/index')
      },
      {
        path: 'user',
        name: '个人中心',
        component: () => import('../views/user/index')
      }]
  },
  //{
    // path: '/about',
    // name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  //}
]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  if (to.matched[0].meta.name) {
    document.title = to.matched[0].meta.name
  }
  next()
})

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
